<%-- 
    Document   : editUser
    Created on : 04.11.2011, 23:58:18
    Author     : Дима
--%>

<%@page import="java.util.GregorianCalendar, java.util.GregorianCalendar"%>
<%@page import="java.util.Calendar"%>
<%@page import="ru.ssau.entities.User"%>
<%@page import="ru.ssau.utils.XMLHelper"%>
<%@page import="org.jdom.Element"%>
<%@page import="ru.ssau.server.Constants"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page errorPage="error.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>   <%
        String userXML = (String) session.getAttribute(Constants.USER);
        User user = null;
        String name = ""; String login = ""; String password = "";
        String info = ""; String year = ""; String month = ""; String day = "";
        String hours = ""; String minutes = ""; String seconds = "";
        if(userXML != null) {
            Element userElement = XMLHelper.parseString(userXML);
            user = new User();
            user.loadFromXMLElement(userElement);
            Calendar c = new GregorianCalendar();
            c.setTime(user.getRegistrationDate());
            year = String.valueOf(c.get(Calendar.YEAR));
            month = String.valueOf(c.get(Calendar.MONTH) + 1);
            day = String.valueOf(c.get(Calendar.DAY_OF_MONTH));
            hours = String.valueOf(c.get(Calendar.HOUR));
            minutes = String.valueOf(c.get(Calendar.MINUTE));
            seconds = String.valueOf(c.get(Calendar.SECOND));
            name = user.getName(); info = user.getInfo();
            login = user.getAuthorizationInfo().getLogin();
            password = user.getAuthorizationInfo().getPassword();
            session.setAttribute(Constants.ID, user.getId());
        } %>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add/edit user</title>

        <style type="text/css">
            h4 {
                margin-top: 6px;
                margin-bottom: 3px;
            }
        </style>
    </head>
    <body>
        <h4>Enter data:</h4>
        <form name="userSetForm" action="request" method="post">
            <table>
                <tr>
                    <td align="right">Name: </td>
                    <td> <input type="text" name="<%=Constants.NAME%>" value="<%=name%>" size="10"/> &nbsp&nbsp </td>
                    <td align="right">Login: </td>
                    <td> <input type="text" name="<%=Constants.LOGIN%>" value="<%=login%>" size="10"/> &nbsp&nbsp </td>
                    <td align="right">Password: </td>
                    <td> <input type="text" name="<%=Constants.PASSWORD%>" value="<%=password%>" size="10"/> </td>
                </tr>
            </table>
            
            <h4>Registration date:</h4>
            <input type="checkbox" <%=(userXML==null)?"checked":""%> name="<%=Constants.DATE_SET_OPTION%>" value="<%=Constants.CURRENT_DATE%>"/>
            Set current date <br>
            <table>
                <tr>
                    <td align="center">Year</td>
                    <td align="center">Month</td>
                    <td align="center">Day</td>
                    <td align="center">Hours</td>
                    <td align="center">Minutes</td>
                    <td align="center">Seconds</td>
                </tr>
                <tr>
                    <td align="center"><input type="text" name="<%=Constants.YEAR%>" value="<%=year%>" size="5"/></td>
                    <td align="center"><input type="text" name="<%=Constants.MONTH%>" value="<%=month%>" size="5"/></td>
                    <td align="center"><input type="text" name="<%=Constants.DAY%>" value="<%=day%>" size="5"/></td>
                    <td align="center"><input type="text" name="<%=Constants.HOURS%>" value="<%=hours%>" size="5"/></td>
                    <td align="center"><input type="text" name="<%=Constants.MINUTES%>" value="<%=minutes%>" size="5"/></td>
                    <td align="center"><input type="text" name="<%=Constants.SECONDS%>" value="<%=seconds%>" size="5"/></td>
                </tr>
            </table>
            Info: <br>
            <textarea name="<%=Constants.INFO%>" cols="25" rows="4" wrap="soft" style="margin-top: 2px; margin-bottom: 10px;"><%=info%></textarea>
            <br>   <%
              if(userXML == null) { %>
                <button name="<%=Constants.ACTION%>" value="<%=Constants.DO_ADD_USER%>">Add user</button>   <%
              } else { %>
                <button name="<%=Constants.ACTION%>" value="<%=Constants.DO_EDIT_USER%>">Edit user</button>   <%
              } %>
        </form>
    </body>
</html>
